'use strict';

module.exports = app => {
    return class MyService extends app.Service {
        constructor(ctx) {
            super(ctx);
        }

        /**
         * 获取教师基本信息
         */

        async getteacherinfo() {
            let url = this.app.urls('getteacherinfo');
            const result = await this.ctx.fetch(url, {
                method: 'get',
                dataType: 'json',
            });
            let data = result.data;

            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data.data;
        }


        /**
         * 获取验证码
         */
        async getyzm(params){
            let url = this.app.urls('getyzm');
            const result = await this.ctx.fetch(url, {
                method: 'get',
                dataType: 'json',
                data:{
                    mobile:params.mobile,
                }
            });
            let data = result.data;

            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data;
        }

        /*
        修改密码
         */
        async editpassword(params){
            let url = this.app.urls('editpassword');
            const result = await this.ctx.fetch(url, {
                method: 'post',
                dataType: 'json',
                data:{
                    mobile:params.mobile,
                    code:params.code,
                    newPassword:params.password,
                }
            });
            let data = result.data;

            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data;
        }

    }
};
